package dev.alm.chatmemorydemo.controller;

import dev.alm.chatmemorydemo.service.ChatMemoryService;
import dev.alm.chatmemorydemo.service.ChatService;
import dev.alm.chatmemorydemo.service.ChatTokenMemoryService;
import dev.alm.chatmemorydemo.service.StreamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("llm")
public class LLMController {

    @Autowired
    private ChatService chatService;

    @Autowired
    private StreamService streamService;

    @Autowired
    private ChatMemoryService chatMemoryService;

    @Autowired
    private ChatTokenMemoryService chatTokenMemoryService;

    @GetMapping("chat")
    public String chat(@RequestParam(value = "question", defaultValue = "你是谁？") String question) {
        return chatService.chat(question);
    }

    @GetMapping("stream")
    public Flux<String> stream(@RequestParam(value = "question", defaultValue = "你是谁？") String question) {
        return streamService.stream(question);
    }

    @GetMapping("chatWithMemory")
    public Flux<String> chatWithMemory(@RequestParam(value = "userId") String userId, @RequestParam(value = "question", defaultValue = "你是谁？") String question) {
//        return chatMemoryService.chatWithMemory(userId, question);
        return chatTokenMemoryService.streamWithMemory(userId, question);
    }

    @GetMapping("chatWithTokenMemory")
    public Flux<String> chatWithTokenMemory(@RequestParam(value = "userId") String userId, @RequestParam(value = "question", defaultValue = "你是谁？") String question) {
//        return chatTokenMemoryService.chatWithMemory(userId, question);
        return chatTokenMemoryService.streamWithMemory(userId, question);
    }

}
